package com.software.myopiaparents.base;


import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.WindowManager;

import com.jaeger.library.StatusBarUtil;
import com.software.myopiaparents.utils.AndroidWorkaround;
import com.software.myopiaparents.view.dialog.DialogWait;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import com.umeng.message.PushAgent;

import butterknife.ButterKnife;
import io.reactivex.Flowable;


/**
 * @author penglei
 *  @date 2020/04/08
 */
public abstract class BaseActivity extends RxAppCompatActivity {

    private Dialog mDlgWait;//等待框

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        StatusBarUtil.setTransparent(this);
        StatusBarUtil.setTranslucentForImageView(this, 0, null);
        StatusBarUtil.setLightMode(this); // 设置app状态栏字体颜色（黑色）
        setContentView(getContentViewId());
        ButterKnife.bind(this);
        mDlgWait = new DialogWait(this);
        mDlgWait.setCancelable(true);
        mDlgWait.setCanceledOnTouchOutside(false);

        //适配虚拟按键
        if (AndroidWorkaround.checkDeviceHasNavigationBar(this)) {
            AndroidWorkaround.assistActivity(findViewById(android.R.id.content));
        }

        // umeng Push后台进行日活统计及多维度推送的必调用方法
        PushAgent.getInstance(this).onAppStart();

        initView();
        initData();

    }

    /**
     * 布局文件ID
     *
     * @return
     */
    protected abstract int getContentViewId();

    /**
     * 控件初始化
     */
    public abstract void initView();

    /**
     * 数据适配
     */
    public abstract void initData();


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();

    }


    /**
     * 显示进度框
     */
    public void showProgress() {
        if (mDlgWait != null && !mDlgWait.isShowing())
            mDlgWait.show();
    }


    /**
     * 关闭进度框
     */
    public void dismissProgress() {
        if (mDlgWait != null && mDlgWait.isShowing())
            mDlgWait.dismiss();
    }


    /**
     * Rx生命周期
     */
    public <T> Flowable<T> rxDestroy(Flowable<T> observable) {
        return observable.compose(this.<T>bindUntilEvent(ActivityEvent.DESTROY));
    }

}
